

package com.light.common.base;

import lombok.Data;

import java.io.Serializable;
import java.util.List;

/**
 * 分页返回类
 *
 * @author yhr
 */
@Data
public class PageResult<T> implements Serializable {
	private static final long serialVersionUID = 1L;
	/**
	 * 总记录数
	 */
	private Integer totalCount;
	/**
	 * 每页记录数
	 */
	private Integer pageSize;
	/**
	 * 总页数
	 */
	private Integer totalPage;
	/**
	 * 当前页数
	 */
	private Integer currentPage;
	/**
	 * 列表数据
	 */
	private List<T> data;
	
	/**
	 * 分页
	 * @param data        列表数据
	 * @param totalCount  总记录数
	 * @param pageSize    每页记录数
	 * @param currentPage    当前页数
	 */
	public PageResult(List<T> data, int totalCount, int pageSize, int currentPage) {
		this.data = data;
		this.totalCount = totalCount;
		this.pageSize = pageSize;
		this.currentPage = currentPage;
		this.totalPage = (int)Math.ceil((double)totalCount/pageSize);
	}

	public PageResult(List<T> data, int totalCount, BaseQuery baseQuery) {
		this.data = data;
		this.totalCount = totalCount;
		this.pageSize = baseQuery.getLimit();
		this.currentPage = baseQuery.getCurrentPage();
		this.totalPage = (int)Math.ceil((double)totalCount/pageSize);
	}

	public List<T> getData() {
		return data;
	}

	public void setData(List<T> data) {
		this.data = data;
	}
	
}
